<?php

/* Page controller class */
class view_posts_handler extends _site_handler {
	public $Posts;
	public $CreatePostUrl;
	public $ShowReplies;
	public $Entity;
	public $Ajax;

	// Render page
	public function __construct($m, $view) {
		$this->InitializeSite($m);

		$this->Wordlets->AddWordlets('view_posts');

		$type = @$_GET['type'];
		$id = @$_GET['id'];
		$posts = NULL;
		$entity = NULL;
		$page->ShowReplies = true;
		$pnum = (intval(@$_GET['pnum']))?intval($_GET['pnum']):1;
		$posts_per_page = Monkake::Get('post_limit');
		$offset = ($pnum-1) * $posts_per_page;
		$this->Ajax = @$_GET['ajax'];

		switch ($type) {
			case ('Post'):
				$entity = Post::GetById($id);
				$page->ShowReplies = false;
				break;
			case ('Smiley'):
				$entity = Smiley::GetById($id);
				break;
			case ('Usr'):
			case ('User'):
				$entity = User::GetById($id);
				break;
			case ('Blog'):
				$entity = Blog::GetById($id);
				break;
		}

		if ( !$entity ) {
			die('fail');
		}

		$entity->SetPostOffset($offset);
		$this->Entity = $entity;

		$page->CreatePostUrl = $entity->CreatePostUrl;

		$this->RenderViewContent($view);
	}
}

?>